package com.example.demo.controller;

import com.example.demo.dto.PoetryListDTO;
import com.example.demo.entity.Author;
import com.example.demo.service.AuthorService;
import com.example.demo.utils.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/author")
public class AuthorController {

    @Resource
    private AuthorService authorService;

    /*获取获取20个诗人*/
    @GetMapping("/someAuthor")
    public Result getSomeAuthor() {
        List<String> list = authorService.getInitAuthorInfo();
        return Result.ok().data("list", list);
    }

    /*随机获取一位每日诗人*/
    @GetMapping("/getRandomAuthor")
    public Result getRandomAuthor() {
        Author author = authorService.getRandomAuthor();
        return Result.ok().data("author", author);
    }

    /*根据诗人id获取该诗人的全部古诗 分页*/
    @GetMapping("/getAuthorPoetryList")
    public Result getAuthorPoetryList(Integer id,Integer pageNo) {
        PoetryListDTO poetryListDTO = authorService.getPoetryListDTO(id,pageNo);
        return Result.ok().data("poetryListDTO", poetryListDTO);
    }

}
